<template>
    <div class="article-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="供应信息">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.name"
                        clearable
						placeholder="请输入药材名称"
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
             <!--   <el-form-item label="审核状态">
                    <el-select class="w-[280px]" v-model="queryParams.start">
                        <el-option label="全部" value />
                        <el-option label="已审核" :value="1" />
                        <el-option label="未审核" :value="0" />
                    </el-select>
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
			<div>
	
			        <el-button type="primary" class="mb-4" @click="batchDeleteFn">
			            批量删除
			        </el-button>
					<!-- <el-button type="primary" class="mb-4" @click="batchPassFn">
					    批量审核通过
					</el-button>
					<el-button type="primary" class="mb-4" @click="batchNotpassedFn">
					    批量审核不通过
					</el-button> -->
			</div>
            <el-table Checkbox="true"
                      type="selection"
                      size="large" v-loading="pager.loading" :data="pager.lists"  @selection-change="handleSelectionChange">
                <el-table-column type="selection" label="ID" prop="id" min-width="80" />
                <el-table-column label="封面" min-width="100">
                    <template #default="{ row }">
                        <image-contain
                            v-if="row.fming"
                            :src="row.fming"
                            :width="60"
                            :height="45"
                            :preview-src-list="[row.fming]"
                            preview-teleported
                            fit="contain"
                        />
                    </template>
                </el-table-column>
                <el-table-column
                    label="药材名称"
                    prop="name"
                    min-width="160"
                    show-tooltip-when-overflow
                />
                <!-- <el-table-column label="品种规格" prop="specifications" min-width="100" /> -->
                <el-table-column label="库存地" prop="producer" min-width="120" />
                <!-- <el-table-column label="浏览量" prop="click" min-width="100" /> -->
              <!--  <el-table-column label="审核状态" min-width="100">
                    <template #default="{ row }">
                        <el-switch
                            v-perms="['article.articleSupply/updateStatus']"
                            v-model="row.start"
                            :active-value="1"
                            :inactive-value="0"
                            @change="changeStatus($event, row.id)"
                        />
                    </template>
                </el-table-column> -->
                <!-- <el-table-column label="排序" prop="sort" min-width="100" /> -->
                <el-table-column label="发布时间" prop="fbtime" min-width="120" />
				<el-table-column label="浏览量" prop="liulan" min-width="120" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['article.articleSupply/edit', 'article.articleSupply/add:edit']"
                            type="primary"
                            link
                        >
                            <router-link
                                :to="{
                                    path: getRoutePath('article.articleSupply/add:edit'),
                                    query: {
                                        id: row.id
                                    }
                                }"
                            >
                                详情
                            </router-link>
                        </el-button>
                        <el-button
                            v-perms="['article.articleSupply/delete']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="supplyLists">
import { supplyLists, sullpyDelete, supplyStatus, batchDelete,batchPass,batchNotpassed } from '@/api/article'
import { usePaging } from '@/hooks/userGongying'
import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'
const queryParams = reactive({
    name: '',
    cid: '',
    start: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: supplyLists,
    params: queryParams
})

const multipleSelection = ref([])
const idArr=ref([])
const handleSelectionChange = (val) => {
  multipleSelection.value = val
   idArr.value=[]
   multipleSelection.value.forEach(item=>{
	   idArr.value.push(item.id)
   })
   
  console.log(multipleSelection.value,'multipleSelection.value');
  console.log(idArr.value,'idArr.value');
}

const changeStatus = async (start: any, id: number) => {
    try {
        await supplyStatus({ id, start })
        getLists()
    } catch (error) {
        getLists()
    }
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await sullpyDelete({ id })
    getLists()
}

onActivated(() => {
    getLists()
})

getLists()



// 批量删除
const batchDeleteFn=async()=>{
	let idA=idArr.value
	let data=await batchDelete({
		idA
	})
	getLists()
}

// 批量审核通过
const batchPassFn=async()=>{
	let idA=idArr.value
	let data=await batchPass({
		idA
	})
	getLists()
}

// 批量审核不通过
const batchNotpassedFn=async()=>{
	let idA=idArr.value
	let data=await batchNotpassed({
		idA
	})
	getLists()
}
</script>
